package com.itao.rocketmq5.normal;

import com.itao.rocketmq5.util.RocketMqFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.apis.ClientException;
import org.apache.rocketmq.client.apis.message.Message;
import org.apache.rocketmq.client.apis.producer.SendReceipt;

import java.nio.charset.StandardCharsets;

/**
 * @Author sjt
 * @CreateTime 2023/10/10 10:39
 */
@Slf4j
public class NormalProducer {
    private final static String NORMAL_TOPIC = "normal_topic";

    public static void main(String[] args) {
        var producer = RocketMqFactory.getProducer(NORMAL_TOPIC);
        var message = RocketMqFactory.provider().newMessageBuilder()
                .setKeys("normalTopicKey")
                .setTag("normalTopic")
                .setTopic(NORMAL_TOPIC)
                .setBody("normalTopicMessage".getBytes(StandardCharsets.UTF_8))
                .build();
        try {
            var sendReceipt = producer.send(message);
            log.info("messageId：{}", sendReceipt.getMessageId());
        } catch (ClientException e) {
            log.error("异常：", e);
        }
    }
}
